package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlLti entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlLti
 * @author MyEclipse Persistence Tools
 */

public class MdlLtiDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory.getLogger(MdlLtiDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String INTRO = "intro";
	public static final String INTROFORMAT = "introformat";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String TYPEID = "typeid";
	public static final String TOOLURL = "toolurl";
	public static final String SECURETOOLURL = "securetoolurl";
	public static final String INSTRUCTORCHOICESENDNAME = "instructorchoicesendname";
	public static final String INSTRUCTORCHOICESENDEMAILADDR = "instructorchoicesendemailaddr";
	public static final String INSTRUCTORCHOICEALLOWROSTER = "instructorchoiceallowroster";
	public static final String INSTRUCTORCHOICEALLOWSETTING = "instructorchoiceallowsetting";
	public static final String INSTRUCTORCUSTOMPARAMETERS = "instructorcustomparameters";
	public static final String INSTRUCTORCHOICEACCEPTGRADES = "instructorchoiceacceptgrades";
	public static final String GRADE = "grade";
	public static final String LAUNCHCONTAINER = "launchcontainer";
	public static final String RESOURCEKEY = "resourcekey";
	public static final String PASSWORD = "password";
	public static final String DEBUGLAUNCH = "debuglaunch";
	public static final String SHOWTITLELAUNCH = "showtitlelaunch";
	public static final String SHOWDESCRIPTIONLAUNCH = "showdescriptionlaunch";
	public static final String SERVICESALT = "servicesalt";
	public static final String ICON = "icon";
	public static final String SECUREICON = "secureicon";

	public void save(MdlLti transientInstance) {
		log.debug("saving MdlLti instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlLti persistentInstance) {
		log.debug("deleting MdlLti instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlLti findById(java.lang.Long id) {
		log.debug("getting MdlLti instance with id: " + id);
		try {
			MdlLti instance = (MdlLti) getSession().get(
					"idv.loveloser.dao.MdlLti", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlLti instance) {
		log.debug("finding MdlLti instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlLti")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlLti instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlLti as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByIntro(Object intro) {
		return findByProperty(INTRO, intro);
	}

	public List findByIntroformat(Object introformat) {
		return findByProperty(INTROFORMAT, introformat);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByTypeid(Object typeid) {
		return findByProperty(TYPEID, typeid);
	}

	public List findByToolurl(Object toolurl) {
		return findByProperty(TOOLURL, toolurl);
	}

	public List findBySecuretoolurl(Object securetoolurl) {
		return findByProperty(SECURETOOLURL, securetoolurl);
	}

	public List findByInstructorchoicesendname(Object instructorchoicesendname) {
		return findByProperty(INSTRUCTORCHOICESENDNAME,
				instructorchoicesendname);
	}

	public List findByInstructorchoicesendemailaddr(
			Object instructorchoicesendemailaddr) {
		return findByProperty(INSTRUCTORCHOICESENDEMAILADDR,
				instructorchoicesendemailaddr);
	}

	public List findByInstructorchoiceallowroster(
			Object instructorchoiceallowroster) {
		return findByProperty(INSTRUCTORCHOICEALLOWROSTER,
				instructorchoiceallowroster);
	}

	public List findByInstructorchoiceallowsetting(
			Object instructorchoiceallowsetting) {
		return findByProperty(INSTRUCTORCHOICEALLOWSETTING,
				instructorchoiceallowsetting);
	}

	public List findByInstructorcustomparameters(
			Object instructorcustomparameters) {
		return findByProperty(INSTRUCTORCUSTOMPARAMETERS,
				instructorcustomparameters);
	}

	public List findByInstructorchoiceacceptgrades(
			Object instructorchoiceacceptgrades) {
		return findByProperty(INSTRUCTORCHOICEACCEPTGRADES,
				instructorchoiceacceptgrades);
	}

	public List findByGrade(Object grade) {
		return findByProperty(GRADE, grade);
	}

	public List findByLaunchcontainer(Object launchcontainer) {
		return findByProperty(LAUNCHCONTAINER, launchcontainer);
	}

	public List findByResourcekey(Object resourcekey) {
		return findByProperty(RESOURCEKEY, resourcekey);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByDebuglaunch(Object debuglaunch) {
		return findByProperty(DEBUGLAUNCH, debuglaunch);
	}

	public List findByShowtitlelaunch(Object showtitlelaunch) {
		return findByProperty(SHOWTITLELAUNCH, showtitlelaunch);
	}

	public List findByShowdescriptionlaunch(Object showdescriptionlaunch) {
		return findByProperty(SHOWDESCRIPTIONLAUNCH, showdescriptionlaunch);
	}

	public List findByServicesalt(Object servicesalt) {
		return findByProperty(SERVICESALT, servicesalt);
	}

	public List findByIcon(Object icon) {
		return findByProperty(ICON, icon);
	}

	public List findBySecureicon(Object secureicon) {
		return findByProperty(SECUREICON, secureicon);
	}

	public List findAll() {
		log.debug("finding all MdlLti instances");
		try {
			String queryString = "from MdlLti";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlLti merge(MdlLti detachedInstance) {
		log.debug("merging MdlLti instance");
		try {
			MdlLti result = (MdlLti) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlLti instance) {
		log.debug("attaching dirty MdlLti instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlLti instance) {
		log.debug("attaching clean MdlLti instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}